package com.wzh.controll;


import com.wzh.pojo.Knowledge;
import com.wzh.service.KnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/knowledge")
public class knowledgeController {

    @Autowired
    private KnowledgeService knowledgeService;

    @GetMapping("/get/")
    public result getAll(){
        List<Knowledge> knowledgeList = knowledgeService.getAll();
        String mes=knowledgeList!=null?"查询成功":"查询失败";
        Integer code=knowledgeList!=null?200:300;
        return new result(mes,code,knowledgeList);
    }

    @PostMapping("/add/")
    public result addKnowledge(@RequestBody Knowledge knowledge){
        boolean flag=knowledgeService.insert(knowledge);
        String mes=flag!=false?"操作成功":"操作失败";
        Integer code=flag!=false?200:300;
        return new result(mes,code,knowledge);
    }

    @PostMapping("/delete/{name}")
    public result deleteKnowledge(@PathVariable String name){
        boolean flag = knowledgeService.delete(name);
        String mes=flag!=false?"操作成功":"操作失败";
        Integer code=flag!=false?200:300;
        return new result(mes,code);
    }

}
